//------------------------------------------------------------------------------
// <copyright file="TavernsCollection.cs" company="Damian Antonowicz">
//       copyright © 2010 Damian Antonowicz
// </copyright>
// <author>Damian Antonowicz</author>
// <email>poczta@damianantonowicz.pl</email>
//------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Xml.Serialization;

namespace DotBeer.Business.Entities
{
    public class TavernsCollection
    {
        #region private members

        ObservableCollection<Tavern> _taverns = new ObservableCollection<Tavern>();

        #endregion

        #region constructors

        public TavernsCollection()
        {
        }

        #endregion

        #region properties

        public ObservableCollection<Tavern> Taverns
        {
            get { return _taverns; }
        }

        [XmlIgnore]
        public ObservableCollection<TavernHero> TavernsHero
        {
            get { return GetTavernsHero(); }
        }

        [XmlIgnore]
        public IEnumerable<Tavern> SentinelTaverns
        {
            get { return GetSentinelTaverns(); }
        }

        [XmlIgnore]
        public IEnumerable<Tavern> ScourgeTaverns
        {
            get { return GetScourgeTaverns(); }
        }

        #endregion

        #region public methods

        public IEnumerable<Tavern> GetTavernsBySide(Side side)
        {
            return _taverns.Where(t => t.Side == side).OrderBy(t => t.Position);
        }

        #endregion

        #region private methods

        private IEnumerable<Tavern> GetSentinelTaverns()
        {
            return GetTavernsBySide(Side.Sentinel);
        }

        private IEnumerable<Tavern> GetScourgeTaverns()
        {
            return GetTavernsBySide(Side.Scourge);
        }

        private ObservableCollection<TavernHero> GetTavernsHero()
        {
            ObservableCollection<TavernHero> tavernsHero = new ObservableCollection<TavernHero>();

            foreach (Tavern tavern in _taverns)
                tavernsHero.Add(new TavernHero() { Name = tavern.Name });

            return tavernsHero;
        }

        #endregion
    }
}
